
import {RECEIVE_ADDRESS,RECEIVE_CATEGORYS,RECEIVE_SHOPS,USER_INFO,LOGIN_OUT,SHOP_GOODS,SHOP_INFO,SHOP_RATINGS} from './mutations-type'

 //SHOP_GOODS   SHOP_INFO   SHOP_RATINGS

//reqShopGoods   reqShopRatings reqShopInfo
import {reqAddress,reqCategorys,reqShops,reqPwdLogin,reqSmsLogin,reqShopGoods,reqShopRatings,reqShopInfo} from '../api/index'
export default{
  //获取商品信息

  async getCategorys(context){

    let result = await reqCategorys()
    // console.log(result.data)
    let categorys=result.data
    context.commit(RECEIVE_CATEGORYS,categorys)
  },
  //获取商家信息
  async reqShops(context,data){
    let result = await reqShops(data)
    console.log(result.data)
    let shops=result.data
    context.commit(RECEIVE_SHOPS,shops)
  },
   //用户名登录
  async reqPwdLogin(context,data){
    let result = await reqPwdLogin(data)

    let userInfo=result.data
    console.log(userInfo)
    context.commit(USER_INFO,userInfo)
  },
  //短信登录
  async reqSmsLogin(context, data) {
    let result = await reqSmsLogin(data)
    console.log(result)
    let userInfo=result.data
    context.commit(USER_INFO,userInfo)
  },
  //获取用户信息
  async getUserInfo(context,data) {
    const result = await reqUser(data)
    console.log(result)
    if(result.code===0) {
      context.commit(USER_INFO,{userInfo: result.data})
    }
      },
  async loginOut (context){
    context.commit(LOGIN_OUT)
  },

  //接收商家信息
  async getShopInfo (context){
    let result =await reqShopInfo()

    if(result.code==0){
      let info =result.data

      context.commit(SHOP_INFO,info)
    }

  },
  //接收商品信息
  async getShopGoods (context,callback){
    let result =await reqShopGoods()
    if(result.code==0){
      let goods =result.data
      console.log(goods)
      context.commit(SHOP_GOODS,{goods})
      callback&&callback()
    }
  },
//接收评论信息
  async getShopRatings (context){
    let result =await reqShopRatings()
    if(result.code==0){
      let ratings =result.data
      context.commit(SHOP_GOODS,{ratings})
    }
  },

  //getShopGoods  getShopInfo getShopRatings
  //SHOP_GOODS   SHOP_INFO   SHOP_RATINGS
}
